﻿<%@ Page Title="Planning" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Tasks.aspx.cs" Inherits="APMAWebConsole.PlanningPart.Tasks" %>
    
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Tasks
    </h2>

    <asp:Button ID="btnAddTask" runat="server" Text="Add Task" OnCommand="OnButtonCommand" CommandName="Add"/>
    <asp:Button ID="btnRemoveTask" runat="server" Text="Remove Task" OnCommand="OnButtonCommand" CommandName="Remove" Visible="false"/>
    <asp:Button ID="btnEditTask" runat="server" Text="Edit Task" OnCommand="OnButtonCommand" CommandName="Edit" Visible="false"/>
    <asp:Button ID="btnBackToList" runat="server" Text="Back to Task List" OnCommand="OnButtonCommand" CommandName="BackToList" CausesValidation="False"/>
        
    <div id="divTasksGrid" runat="server">
        <p>
            <asp:Label ID="lblSelectedTask" runat="server" AssociatedControlID="txtSelectedTask" Text="Selected Task ID:" Visible="false"/>
            <asp:TextBox ID="txtSelectedTask" runat="server" CssClass="textEntry" Text="0" Visible="false"/>
        </p>
        <asp:GridView ID="grdTasks" runat="server" AutoGenerateColumns="false">
            <columns>
                <asp:BoundField HeaderText="ID" DataField="Id" />
                
                <asp:TemplateField HeaderText="" ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button ID="btnEdit" runat="server" CausesValidation="false" Text="Edit" OnCommand="OnButtonCommand" CommandName="Select" CommandArgument='<%# Container.DataItemIndex + 1 %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="" ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button ID="btnRemove" runat="server" CausesValidation="false" Text="X" OnCommand="OnButtonCommand" CommandName="Remove" CommandArgument='<%# Container.DataItemIndex + 1 %>'/>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:BoundField HeaderText="Name" DataField="Name" />
                <asp:BoundField HeaderText="Owner" DataField="Owner" />
                <asp:BoundField HeaderText="Project" DataField="Project" />
                <%-- <asp:BoundField HeaderText="Description" DataField="Description" /> --%>
                <asp:BoundField HeaderText="State" DataField="State" />
                <asp:BoundField HeaderText="Estimate" DataField="Estimate" />
                <asp:BoundField HeaderText="Actuals" DataField="Actuals" />
                <asp:BoundField HeaderText="TO DO" DataField="To_do" />
                <asp:BoundField HeaderText="User Story" DataField="User Story" />
                <%-- <asp:BoundField HeaderText="Notes" DataField="Notes" /> --%>
            </columns>
        </asp:GridView>
    </div>
        
    <div id="divEditMode" runat="server">
                <asp:ScriptManager ID="ScriptManager1" 
                               runat="server" />
        <p>
            <asp:Label ID="lblTaskId" runat="server" AssociatedControlID="txtTaskId">ID:</asp:Label>
            <asp:TextBox ID="txtTaskId" runat="server" CssClass="textEntry"></asp:TextBox>
        </p>
        <p>
            <asp:Label ID="lblTaskName" runat="server" AssociatedControlID="txtTaskName">Name:</asp:Label>
            <asp:TextBox ID="txtTaskName" runat="server" CssClass="textEntry"></asp:TextBox>
            <asp:RequiredFieldValidator id="rfvTaskName" runat="server"
                                        ControlToValidate="txtTaskName"
                                        ErrorMessage=" * Task name is a required field."
                                        ForeColor="Red"/>
            <br/>
            <asp:RegularExpressionValidator id="revTaskName" runat="server" SetFocusOnError="True"
                                            ErrorMessage="Task Name length must be between 4 and 50 characters" Display="Dynamic"
                                            ControlToValidate="txtTaskName" ValidationExpression="^[\s\S]{4,50}$"/>
        </p>
        <p>
            <asp:Label ID="lblTaskOwnerId" runat="server" AssociatedControlID="ddlTaskOwnerId">Owner:</asp:Label>
            <asp:DropDownList ID="ddlTaskOwnerId" runat="server" />
        </p>
        <p>
            <asp:Label ID="lblTaskProjectId" runat="server" AssociatedControlID="ddlTaskProjectId">Project:</asp:Label>
            <asp:DropDownList ID="ddlTaskProjectId" runat="server" />
            <asp:RequiredFieldValidator id="rfvTaskProjectId" runat="server"
                                        ControlToValidate="ddlTaskProjectId"
                                        ErrorMessage=" * Task Project is a required field."
                                        ForeColor="Red"/>
        </p>
        <p>
            <asp:Label ID="lblTaskDescription" runat="server" AssociatedControlID="txtTaskDescription">Description:</asp:Label>
            <asp:TextBox ID="txtTaskDescription" runat="server" CssClass="textEntry"></asp:TextBox>
            <br/>
            <asp:RegularExpressionValidator id="revTaskDescription" runat="server" SetFocusOnError="True"
                                            ErrorMessage="Task Description length must not be more than 200 characters" Display="Dynamic"
                                            ControlToValidate="txtTaskDescription" ValidationExpression="^[\s\S]{0,200}$"/>
        </p>
        <p>
            <asp:Label ID="lblTaskStateId" runat="server" AssociatedControlID="ddlTaskStateId">State:</asp:Label>
            <asp:DropDownList ID="ddlTaskStateId" runat="server" />
            <asp:RequiredFieldValidator id="rfvTaskStateId" runat="server"
                                        ControlToValidate="ddlTaskStateId"
                                        ErrorMessage=" * Task state is a required field."
                                        ForeColor="Red"/>
        </p>
        <p>
            <asp:Label ID="lblTaskEstimate" runat="server" AssociatedControlID="txtTaskEstimate">Estimate:</asp:Label>
            <asp:TextBox ID="txtTaskEstimate" runat="server" CssClass="textEntry"></asp:TextBox>
            <br/>
            <asp:RangeValidator id="revTaskEstimate" runat="server"
                                        ControlToValidate="txtTaskEstimate"
                                        MinimumValue="0"
                                        MaximumValue="2147483647"
                                        Type="Integer"
                                        Text="Task Estimate must be integer and greater or equal than 0"/>
        </p>
        <p>
            <asp:Label ID="lblTaskActuals" runat="server" AssociatedControlID="txtTaskActuals">Actuals:</asp:Label>
            <asp:TextBox ID="txtTaskActuals" runat="server" CssClass="textEntry"></asp:TextBox>
            <br/>
            <asp:RangeValidator id="revTaskActuals" runat="server"
                                        ControlToValidate="txtTaskActuals"
                                        MinimumValue="0"
                                        MaximumValue="2147483647"
                                        Type="Integer"
                                        Text="Task Actuals must be integer and greater or equal than 0"/>
        </p>
        <p>
            <asp:Label ID="lblTaskToDo" runat="server" AssociatedControlID="txtTaskToDo">To do:</asp:Label>
            <asp:TextBox ID="txtTaskToDo" runat="server" CssClass="textEntry"></asp:TextBox>
            <br/>
            <asp:RangeValidator id="revTaskToDo" runat="server"
                                        ControlToValidate="txtTaskToDo"
                                        MinimumValue="0"
                                        MaximumValue="2147483647"
                                        Type="Integer"
                                        Text="Task To Do must be integer and greater or equal than 0"/>
        </p>
        <p>
            <asp:Label ID="lblTaskUserStoryId" runat="server" AssociatedControlID="ddlTaskUserStoryId">User Story:</asp:Label>
            <asp:DropDownList ID="ddlTaskUserStoryId" runat="server" />
        </p>
        <p>
            <asp:Label ID="lblTaskNotes" runat="server" AssociatedControlID="txtTaskNotes">Notes:</asp:Label>
            <asp:TextBox ID="txtTaskNotes" runat="server" CssClass="textEntry"></asp:TextBox>
            <asp:RegularExpressionValidator id="revTaskNotes" runat="server" SetFocusOnError="True"
                                            ErrorMessage="Task Notes length must not be more than 200 characters" Display="Dynamic"
                                            ControlToValidate="txtTaskNotes" ValidationExpression="^[\s\S]{0,200}$"/>
        </p>
        <asp:UpdatePanel id="updUploadFiles" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                
                <script type="text/javascript">

                    function onInputUploadFileChange(tar) {
                        if (tar) {
                            <%=Page.ClientScript.GetPostBackEventReference(btnServerFileUpload,"") %>
                        }
                    }

                </script>

                <p>Uploaded files</p>
                <asp:GridView ID="grdUploadedFiles" runat="server" AutoGenerateColumns="false">
                    <columns>
                        <asp:BoundField HeaderText="ID" DataField="Id" />
                        <asp:BoundField HeaderText="Name" DataField="Name" />
                    </columns>
                </asp:GridView>
                <p>
                    Select a file to upload:<br />
                    <input type="file" id="inputUploadFile" runat="server" onchange="onInputUploadFileChange(this);" />
                </p>
                <p>
                    <asp:Button ID="btnRemoveLast" runat="server" Text="Remove last added file" OnClick="btnRemoveLast_OnClick" CausesValidation="False"/>
                </p>

            </ContentTemplate>
        </asp:UpdatePanel>
                        <p>
                    <asp:TextBox ID="txtDownloadFileID" runat="server" CssClass="textEntry" Text="1" />
                    <asp:Button ID="btnDownloadFile" runat="server" Text="Download file" OnClick="btnDownloadFile_OnClick" CausesValidation="False"/>
                </p>

        <asp:Button ID="btnCreateUpdate" runat="server" Text="Save" OnCommand="OnButtonCommand" CommandName="SaveUpdate"/>
        <asp:Button style="display:none" runat="server" ID="btnServerFileUpload" UseSubmitBehavior="false" OnClick="btnServerFileUpload_Click" />
    </div>
</asp:Content>
